package io.zhengsh.vvip.leetcode.binarysearch;

public class Q278_First_Bad_Version {

    static public class Solution extends VersionControl {
        public int firstBadVersion(int n) {
            int left = 1, right = n;
            while (left < right) { // 循环直到左右两边相等
                int mid = ((right - left) / 2) + left;
                if (isBadVersion(mid)) {
                    right = mid; //答案区间在 [left, mid]
                } else {
                    left = mid + 1; // 答案区间在 [mid + 1, right]
                }
            }
            // 此刻 left == right 区间缩为一个点，即为答案
            return left;
        }
    }

    static public class VersionControl {
        boolean isBadVersion(int version) {
            return true;
        }
    }

}
